<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="ext.tianma.upload.Files"%>
<%@page import="ext.tianma.bom.util.GenericUtil"%>
<%@page import="ext.tianma.util.TMUtil"%>
<%@page import="ext.tianma.part.AVLMaterial.AVLUtil"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="wt.httpgw.HTTPRequest"%>
<%@page import="wt.part.WTPart"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="ext.tianma.upload.SmartUpload"%>
<%@page import="wt.util.WTProperties" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ImportDocInfor</title>
</head>
<body>
	<%
		String SelectUploadFile = "文件不存在";
		String oid = request.getParameter("oid");
		String wid = request.getParameter("wid"); //流程oid
		
		SmartUpload mySmartUpload = new SmartUpload();
		WTDocument doc = null;
		String name = "";
		String showName = "";
		File saveFile = null;
		List<File> docFiles = new ArrayList<File>();
		try {
		    mySmartUpload.initialize(pageContext);  //初始化
		    mySmartUpload.upload();
		    //如果是要上载主要内容，可以参考importDoc.jsp
		    //批量上载附件到文档
		    Files files = mySmartUpload.getFiles();
		    if (null != files && files.getCount() > 0){
		        doc = (WTDocument) TMUtil.oid2Obj(oid);
		        String wthome = (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "");
		        for(int i = 0 ; i < files.getCount(); i++) {
		        	ext.tianma.upload.File myFile = mySmartUpload.getFiles().getFile(i);
			        name = myFile.getFileName();//取得文件名
			        String saveurl = wthome + File.separator + "temp" + File.separator;
			        saveurl += name ; 
			        myFile.saveAs(saveurl, mySmartUpload.SAVE_PHYSICAL);
			        saveFile = new File(saveurl);
			        docFiles.add(saveFile);
		        }
		        AVLUtil.updateSecondaryFromDoc(doc, docFiles);
		    } else {
		    	%>
				<SCRIPT language=javascript>
	                alert("文档为空！");
	                window.close();
	            </SCRIPT>
				<% 
		    }
		} catch (java.lang.StringIndexOutOfBoundsException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (doc != null) {
			%>
            <SCRIPT language=javascript>
                alert("文档上传成功");
                self.opener.location.reload();
                window.close();
            </SCRIPT>
            <%
		} else {
			%>
            <SCRIPT language=javascript>
                alert("文档上传失败，请联系管理员");
                window.close();
            </SCRIPT>
            <%
		}
	%>
</body>
</html>
